﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class BeginManage : Singleton<BeginManage> {

    /// <summary>
    /// 获取开始界面的三个按钮对应的Image界面
    /// </summary>
    public Transform[] optionsBg;
    public Button musicSet;
    [SerializeField, Tooltip("获取音乐的类")]
    public ObtainMusic obm=null;
    /// <summary>
    /// 初始化
    /// </summary>
    void Start()
    {
        #region 界面初始化
        UIshower.Instance.StartPlay(0);
        #endregion
#if DEBUG
        if (File.Exists(Application.persistentDataPath + @"/CpScore.yzc"))
        {
            ArrayList aList = new ArrayList();
            aList = TextClass.Instance.Load(true);
            foreach (SaveScores ss in aList)
            {
                print(ss.IsOPen.ToString() + "  " + ss.Score.ToString() + "  " + ss.CheckPoint.ToString());
            }
        }

#endif
        if (!File.Exists(Application.persistentDataPath + @"/CpScore.yzc"))
        {
            print("不存在");
            TextClass.Instance.Save(TextClass.Instance.Creat(false), "CpScore.yzc");
        }//判断文件是否存在
    }

    private void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            Exit();
            Time.timeScale = 0;
        }
    }
    public void PickOff()
    {
        if (SetMManager.Instance != null)
            SetMManager.Instance.PlayMusic(1);
        SceneManager.LoadScene(1);
    }//开始选关
    public void Helping()
    {
        if (SetMManager.Instance != null)
            SetMManager.Instance.PlayMusic(0);
        UIshower.Instance.RecPlay(0);
        UIshower.Instance.StartPlay((Nodeal)1);
    }//帮助界面
    public void RetBack()
    {
        if (SetMManager.Instance != null)
            SetMManager.Instance.PlayMusic(0);
        UIshower.Instance.RecPlay((Nodeal)1);
        UIshower.Instance.StartPlay(0);
    }//返回开始界面

    public void Exit()
    {
        UIshower.Instance.StartPlay(Nodeal.Quit);
    }//结束游戏

    public override void FixedAwake()
    {
        optionsBg = new Transform[2];
        int i = 0;
        foreach (Transform child in transform)
        {
            if (i == 2) break;
            optionsBg[i] = child;
            i++;
        }
    }
    
}
